package org.wen.soft.generate.util;

import java.util.Arrays;
import java.util.List;

public class ExcludeUtil {

    public static final List<String> basicClassNames = Arrays.asList(
            "byte",
            "char",
            "boolean",
            "short",
            "int",
            "long",
            "float",
            "double"
    );

    public static final List<String> basicArrayClassNames = Arrays.asList(
            "byte[]",
            "char[]",
            "boolean[]",
            "short[]",
            "int[]",
            "long[]",
            "float[]",
            "double[]"
    );

    public static final List<String> basicObjectClassNames = Arrays.asList(
            "java.lang.Byte",
            "java.lang.Character",
            "java.lang.Boolean",
            "java.lang.Short",
            "java.lang.Integer",
            "java.lang.Long",
            "java.lang.Float",
            "java.lang.Double"
    );

    public static final List<String> basicObjectArrayClassNames = Arrays.asList(
            "java.lang.Byte[]",
            "java.lang.Character[]",
            "java.lang.Boolean[]",
            "java.lang.Short[]",
            "java.lang.Integer[]",
            "java.lang.Long[]",
            "java.lang.Float[]",
            "java.lang.Double[]"
    );

    public static final List<String> otherObjectClassNames = Arrays.asList(
            "java.lang.String",
            "java.lang.Object"
    );

    public static final List<String> otherObjectArrayClassNames = Arrays.asList(
            "java.lang.String[]",
            "java.lang.Object[]"
    );

    public static final List<String> invokeTypeSubclassNames = Arrays.asList(
            "java.util.List",
            "java.util.ArrayList",
            "java.util.LinkedList",
            "java.util.AbstractList",
            "java.util.AbstractCollection",
            "java.util.AbstractMap",
            "java.util.AbstractSet",
            "java.util.AbstractQueue",
            "java.util.Collection",
            "java.util.Map",
            "java.util.HashMap"
    );

    private static boolean defExclude(String classTypeName) {
        if (basicClassNames.contains(classTypeName)){
            return true;
        }
        if (basicArrayClassNames.contains(classTypeName)){
            return true;
        }
        if (basicObjectClassNames.contains(classTypeName)){
            return true;
        }
        if (basicObjectArrayClassNames.contains(classTypeName)){
            return true;
        }
        if (otherObjectClassNames.contains(classTypeName)){
            return true;
        }
        return otherObjectArrayClassNames.contains(classTypeName);
    }


    /**
     * 指定class是否是导入排除类
     */
    public static boolean importExclude(String classTypeName) {
        return defExclude(classTypeName);
    }

    /**
     * 是否是字段注入排除类型
     */
    public static boolean mockFieldExclude(String classTypeName){
        if ("void".equals(classTypeName)) {
            return true;
        }
        if (invokeTypeSubclassNames.contains(classTypeName)) {
            return true;
        }
        return defExclude(classTypeName);
    }

    /**
     * 是否是静态类mock排除类型：如String.valueOf()通常不需要作为静态mock处理
     */
    public static boolean mockStaticClassExclude(String classTypeName){
        if ("java.util.logging.Logger".equals(classTypeName)) {
            return true;
        }
        return defExclude(classTypeName);
    }

    /**
     * 禁止mock代理的对象
     */
    public static boolean mockProxyClassExclude(String classTypeName){
        if ("java.util.logging.Logger".equals(classTypeName)) {
            return true;
        }
        if ("void".equals(classTypeName)) {
            return true;
        }
        if (invokeTypeSubclassNames.contains(classTypeName)) {
            return true;
        }
        return defExclude(classTypeName);
    }

}
